package com.tanovo.api;

import com.tanovo.bo.FileBo;
import com.tanovo.bo.ResultObject;
import com.tanovo.service.IFileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Api(tags = "文件上传")
@RequestMapping("file")
@Slf4j
public class FileUploadApi {

    @Autowired
    private IFileUploadService iFileUploadService;


    @ApiOperation(value = "私有-上传文件", notes = "私有-上传文件")
    @PostMapping("/private/upload")
    public ResultObject<FileBo> privateUpload(@RequestParam("file") MultipartFile file) {
        log.info("文件的名称：{}", file.getOriginalFilename());
        FileBo fileBo = iFileUploadService.privateAliyunUpload(file);
        return new ResultObject(fileBo);
    }

    @ApiOperation(value = "获取私有文件临时地址", notes = "获取私有文件临时地址")
    @GetMapping("/temp/getfileUrl")
    public ResultObject getTempUrl(@RequestParam String filePath) {
        String path = iFileUploadService.getInternetUrl(filePath);
        return new ResultObject(path);
    }

    @ApiOperation(value = "公有-上传文件", notes = "公有-上传文件")
    @PostMapping("/public/upload")
    public ResultObject<FileBo> publicUpload(@RequestParam("file") MultipartFile file) {
        log.info("文件的名称：{}", file.getOriginalFilename());
        FileBo fileBo = iFileUploadService.publicAliyunUpload(file);
        return new ResultObject(fileBo);
    }

}
